package com.example.user.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.user.dao.po.Role;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {

    @Select("SELECT DISTINCT p.perm_key FROM permission p " +
            "INNER JOIN sys_role_permission rp ON p.id = rp.perm_id " +
            "INNER JOIN sys_user_role ur ON rp.role_id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<String> selectPermIdsByUserId(@Param("userId") Long userId);

    @Select("SELECT DISTINCT p.role FROM role p " +
            "INNER JOIN sys_user_role ur ON p.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<String> selectRoleKeysByUserId(@Param("userId") Long userId);
}
